import random

import backend
from backend import Rectangle


def test_scene_init():
    default_dict = {'danger_level': 0, 'name': 'scene',
                    'floors': {(7, 3), (4, 7), (1, 3), (6, 6), (5, 6), (5, 4), (6, 2), (1, 6), (3, 7), (2, 5), (8, 5),
                               (7, 2), (1, 2), (6, 7), (3, 3), (7, 6), (4, 4), (6, 3), (1, 5), (5, 8), (3, 6), (2, 2),
                               (8, 6), (3, 5), (6, 4), (3, 2), (2, 6), (8, 2), (4, 5), (5, 5), (1, 4), (7, 7), (5, 9),
                               (7, 5), (2, 3), (8, 7), (4, 2), (6, 5), (5, 3), (2, 7), (8, 3), (4, 6), (5, 2), (5, 7),
                               (7, 4), (4, 3), (1, 7), (3, 4), (2, 4), (8, 4)},
                    'items': set([]), 'traps': set([]),
                    'explored': [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                                 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],
                    'height': 10, 'width': 10, 'seed': None,
                    'grid': [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
                             [1, 1, 0, 0, 0, 0, 0, 0, 1, 1],
                             [1, 1, 0, 0, 0, 0, 0, 0, 1, 1],
                             [1, 1, 0, 0, 0, 0, 0, 0, 1, 1],
                             [1, 1, 0, 0, 0, 0, 0, 0, 1, 1],
                             [1, 1, 0, 0, 0, 0, 0, 0, 2, 0],
                             [1, 1, 0, 0, 0, 0, 0, 0, 1, 1],
                             [1, 1, 0, 0, 0, 0, 0, 0, 1, 1],
                             [1, 1, 0, 0, 0, 0, 0, 0, 1, 1],
                             [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]],
                    'rooms': [Rectangle((50, 31), (58, 40)), Rectangle((48, 19), (56, 24)), Rectangle((44, 2), (51, 12)),
                              Rectangle((33, 32), (40, 38)), Rectangle((32, 22), (39, 29)), Rectangle((22, 33), (31, 41)),
                              Rectangle((23, 20), (31, 30)), Rectangle((33, 1), (41, 7)), Rectangle((23, 4), (30, 14)),
                              Rectangle((11, 26), (16, 33)), Rectangle((1, 24), (6, 32)), Rectangle((12, 13), (18, 19)),
                              Rectangle((12, 2), (18, 10)), Rectangle((3, 12), (9, 22)), Rectangle((1, 2), (8, 7))],
                    'doors': {(49, 18), (30, 15), (31, 7), (7, 31), (22, 20), (47, 20), (25, 31), (32, 20), (32, 7),
                              (15, 12), (25, 32), (49, 25), (30, 19), (49, 13), (36, 31), (36, 30), (5, 8)},
                    'fov_map': 'override', 'units': set([]), 'path': 'override', 'wall_type': 1, 'floor_type': 0,
                    'stairs': set([]), 'dirty': set([])}
    random.seed(0)
    s = backend.Scene(10, 10, 0, 1)
    s.fov_map = 'override'
    s.path = 'override'
    for key in s.__dict__.keys():
        yield check_default_scene, s.__dict__[key], default_dict[key]

def check_default_scene(s_value, d_value):
    assert s_value == d_value


def test_kill():
    class MockUnit(int):
        def die(self):
            pass
    s = backend.Scene(2, 2, 0, 1, 'test')
    s.units = {MockUnit(1), MockUnit(2), MockUnit(3), MockUnit(4), MockUnit(5)}
    s.kill({MockUnit(2), MockUnit(3), MockUnit(4)})
    assert s.units == {MockUnit(1), MockUnit(5)}
